package com.tuoren.forward.init;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import com.tuoren.forward.interceptor.MybatisInterceptor;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class MybatisInit implements ApplicationRunner{
	
	@Autowired
	@Qualifier("primarySqlSessionFactory")
	SqlSessionFactory primarySqlSessionFactory;
	
	
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// TODO Auto-generated method stub
		log.info("Mybatis 初始化, 保证MybatisInterceptor 优先执行>>>>");
		primarySqlSessionFactory.getConfiguration().addInterceptor(new MybatisInterceptor());
	}

}
